package com.jwaoo.mobile.view.main;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import com.dx.as.ui.CircleImageView;
import com.jwaoo.mobile.R;
import com.jwaoo.mobile.view.setting.SettingActivity;
import com.jwaoo.mobile.view.user.UserActivity;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by jwaoo on 2018/3/21.
 */

public class MenuView {
    private View view;
    private Activity activity;
    private View.OnClickListener onLoginOutListener;
    public MenuView(Activity activity, View view , View.OnClickListener onLoginOut){
        this.activity = activity;
        this.view = view;
        this.onLoginOutListener = onLoginOut;
        initMenu();
    }

    private void initMenu(){
        view.findViewById(R.id.message_item_portrait_left).setOnClickListener(onClickListener);
        view.findViewById(R.id.my_wallet).setOnClickListener(onClickListener);
        view.findViewById(R.id.vip_center).setOnClickListener(onClickListener);
        view.findViewById(R.id.authentication).setOnClickListener(onClickListener);
        view.findViewById(R.id.system_message).setOnClickListener(onClickListener);
        view.findViewById(R.id.setting).setOnClickListener(onClickListener);
        view.findViewById(R.id.loginout).setOnClickListener(this.onLoginOutListener);
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Class<?> clas = null;
            switch (v.getId()){
                case R.id.my_wallet:
                    break;
                case R.id.vip_center:
                    break;
                case R.id.authentication:
                    break;
                case R.id.system_message:
                    break;
                case R.id.setting:
                    clas = SettingActivity.class;
                    break;
                case R.id.message_item_portrait_left:
                    clas = UserActivity.class;
                    break;
            }
            goToNewActivity(clas);
        }
    };

    public void goToNewActivity(Class<?> clas){
        Intent intent = new Intent(activity,clas);
        activity.startActivity(intent);
    }

    public void setNickName(String nickName){
        ((TextView)view.findViewById(R.id.nickname)).setText(nickName);

    }

    public void setAvatar(String url){
        ImageLoader.getInstance().displayImage(url,(CircleImageView)view.findViewById(R.id.message_item_portrait_left));
    }


}
